<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        canvas {
            border:1px solid red;
        }
    </style>
</head>
<body>
    <canvas width="500" height="400"></canvas>
    <script>
        window.onload = function(){
            //1:获取canvas对象
            let c = document.querySelector('canvas');
            //2：创建实例
            let ctx = c.getContext('2d');
            //3：设置起始点(x,y)横纵坐标是一canvas的左上角为原点
            ctx.moveTo(100,100);
            //4:设置中点的坐标
            ctx.lineTo(300,100);
            //5:设置线的颜色
            ctx.strokeStyle = 'blue';
            //6:画线
            ctx.stroke()
            //7:重置路劲
            ctx.beginPath()
            //再画一条
            ctx.moveTo(100,300);
            ctx.lineTo(300,300);
            ctx.strokeStyle = 'red';
            ctx.stroke();
            ctx.beginPath()

        }
    </script>
</body>
</html>